(function($, window) {
	var baseRequest = window.baseRequest;
	var appConfig = window.appConfig;
	var commonTool = window.commonTool;
	var dataManager = window.dataManager;
	var locale = dataManager.getLocale();
	var baseUrl = appConfig.v3ServiceUrl + '/stamonitor';

	var v3StaMonitor = window.v3StaMonitor = {};

	//add by ding

	//terminalType : "2g","5g","all"
	v3StaMonitor.getTerminalList = function(devSN, startIndex, terminalType, callback) {
		var getTerminalListUrl = "";
		if(terminalType === "2g") {
			getTerminalListUrl = baseUrl + "/app/stalist_2_4G?";
		} else if(terminalType === "5g") {
			getTerminalListUrl = baseUrl + "/app/stalist_5G?";
		} else {
			getTerminalListUrl = baseUrl + "/app/stalist?";
		}
		baseRequest.commonGet(getTerminalListUrl + $.param({
			devSN: devSN,
			startNum: startIndex
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	//根据mac获取终端信息 /stamonitor/app/stainfo?devSN=' + acSN + '&clientMAC=
	var getTerminalDetailByMacUrl = baseUrl + '/app/stainfo?';
	v3StaMonitor.getTerminalDetailByMac = function(devSN, clientMac, callback) {
		baseRequest.commonGet(getTerminalDetailByMacUrl + $.param({
			devSN: devSN,
			clientMAC: clientMac
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	//获取终端厂商分布
	var terminalStatisticsByManufacturerUrl = baseUrl + "/getclientstatisticbybyod?";
	v3StaMonitor.getTerminalStatisticsByManufacturer = function(devSN, callback) {
		baseRequest.commonGet(terminalStatisticsByManufacturerUrl + $.param({
			devSN: devSN
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2)
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	var getTerminalStatisticsByWirelessUrl = baseUrl + "/getclientstatisticbymode?";
	v3StaMonitor.getTerminalStatisticsByWireless = function(devSN, callback) {
		baseRequest.commonGet(getTerminalStatisticsByWirelessUrl + $.param({
			devSN: devSN
		}), 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2)
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	var getTerminalCountUrl = baseUrl + "/getclientstatisticbybandtype?";
	v3StaMonitor.getTerminalCount = function(devSN, callback) {
		baseRequest.commonGet(getTerminalCountUrl + $.param({
			devSN: devSN
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	var getTerminalStatisticsBySsidUrl = baseUrl + "/getclientstatisticbyssid?";
	v3StaMonitor.getTerminalStatisticsBySsid = function(devSN, callback) {
		baseRequest.commonGet(getTerminalStatisticsBySsidUrl + $.param({
			devSN: devSN
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	//end

	//AP上线终端数
	var getApStaticByClientNumUrl = baseUrl + '/getapstaticbyclientnum?';
	v3StaMonitor.getApStaticByClientNum = function(devSN, callback) {
		baseRequest.commonGet(getApStaticByClientNumUrl + $.param({
			devSN: devSN
		}), 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		})
	};
	// 历史客流统计
	var histClientStatistic = baseUrl + '/histclientstatistic_bycondition';
	v3StaMonitor.getHistClientStatistic = function(devSN, nasId, type, callback) {
		baseRequest.commonGet(histClientStatistic + '?' + $.param({
			devSN: devSN,
			dataType: type,
			nasId: nasId,
			_: +new Date()
		}), 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(data == -1 || data.errcode) {
				return callback(1, locale.base.err.request);
			}
			callback(0, data.histclientList);
		});
	};

	//add by wangyu
	var clientDetail = baseUrl + '/clientOnline';
	v3StaMonitor.getClientDetail = function(devSN, shopId, Mac, callback){
		baseRequest.commonPost(clientDetail, {
			method: 'getOneClientOnlineData',
			param: {
				devSN: devSN,
				shopId: shopId,
				clientMAC: Mac
			}
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.retCode) {
					callback(1);
				} else {
					callback(0, data.data);
				}
			}
		})
	}
	
	var kpistanum = baseUrl + '/app/objapnum?';
	v3StaMonitor.getKpistanum = function(devSN, callback) {
		baseRequest.commonPost(kpistanum + $.param({
			devSN: devSN,
			objNum: 31
		}), {}, 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	
	var bySsidAndMode = baseUrl + '/getclientlist_byssidandmode?';
	v3StaMonitor.getBySsidAndMode = function(devSN, ssid, skipnum, checkdata, callback){
		baseRequest.commonPost(bySsidAndMode + $.param({
			devSN: devSN,
			mode: 'all',
			ssid: ssid,
			skipnum: skipnum,
			limitnum: 10
		}), checkdata, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1) {
					callback(1);
				} else {
					callback(0, data.clientList);
				}
			}
		})
	}
	
	var clientLoadFactor = baseUrl + '/clientloadonap';
	v3StaMonitor.getClientLoadFactor = function(nasid, type, callback){
		baseRequest.commonPost(clientLoadFactor, {
			method: "clientLoadOnApDetail",
			param: {
				scenarioid: nasid,
				type: type
			}
		}, 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.clientloadonap.errCode) {
					callback(1);
				} else {
					callback(0, data.clientloadonap.data);
				}
			}
		})
	}

	var clientValue = baseUrl + '/clientstreamvalue?';
	v3StaMonitor.getClientValue = function(nasid, callback) {
		baseRequest.commonPost(clientValue, {
			method: "clientDownStream",
			param: {
				scenarioid: nasid
			}
		}, 10000, function(code, data) {
//			data = JSON.parse(data);
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data.response);
				}
			}
		})
	}
	
	var throuhput = baseUrl + '/clientloadonap?';
	v3StaMonitor.getThrouhput = function(nasid, callback) {
		baseRequest.commonPost(throuhput, {
			method: "clientLoadOnApDistribuStat",
			param: {
				scenarioid: nasid
			}
		}, 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.clientloadonap.errCode) {
					callback(1);
				} else {
					callback(0, data.clientloadonap.data);
				}
			}
		})
	}
	
	var throuhputtop5 = baseUrl + '/clientloadonap?';
	v3StaMonitor.getThrouhputTop5 = function(nasid, callback) {
		baseRequest.commonPost(throuhputtop5, {
			method: "clientLoadOnHeavyApTop20",
			param: {
				scenarioid: nasid
			}
		}, 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.clientloadonap.errCode) {
					callback(1);
				} else {
					callback(0, data.clientloadonap.data);
				}
			}
		})
	}
	
	var clientListCont = baseUrl + '/getclientlistbycondition?';
	v3StaMonitor.getClientListCont = function(devSN, callback){
		baseRequest.commonGet(clientListCont + $.param({
			devSN: devSN,
			reqType: 'all'
		}), 10000, function(code, data){
			if(code === 2 || code === 1) {
				return callback(2)
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data.clientList);
				}
			}
		})
	}

	var kpiclient5G = baseUrl + '/aplist_5Gclient?';
	v3StaMonitor.getkpiclient5G = function(devSN, callback) {
		baseRequest.commonGet(kpiclient5G + $.param({
			devSN: devSN,
			objNum: 50
		}), 10000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2)
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		})
	}
	//end

	//add by wuchengcheng
	//终端关键指标
	var getClientCountUrl = baseUrl + "/app/stalist?";
	v3StaMonitor.getClientCount = function(devSN, startNum, callback) {
		baseRequest.commonGet(getClientCountUrl + $.param({
			devSN: devSN,
			startNum: startNum
		}), 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	var getRssiurl = baseUrl + "/stationlist_fuzzy?";
	v3StaMonitor.getRssi = function(devSN, skipnum, limitnum, callback) {
		baseRequest.commonPost(getRssiurl + $.param({
				devSN: devSN,
				skipnum: skipnum,
				limitnum: limitnum
			}), {
				findoption: {
					signalStrength: {
						min: 1,
						max: 14
					}
				},
				sortoption: {}
			},
			5000,
			function(code, data) {
				if(code === 2 || code === 1) {
					return callback(2);
				}
				if(code === 0) {
					if(data == -1 || data.errcode) {
						callback(1);
					} else {
						callback(0, data);
					}
				}
			});
	}

	var get11burl = baseUrl + "/stationlist_fuzzy?";
	v3StaMonitor.get11b = function(devSN, skipnum, limitnum, callback) {
		baseRequest.commonPost(get11burl + $.param({
				devSN: devSN,
				skipnum: skipnum,
				limitnum: limitnum
			}), {
				findoption: {
					clientMode: "802.11b"
				},
				sortoption: {}
			},
			5000,
			function(code, data) {
				if(code === 2 || code === 1) {
					return callback(2);
				}
				if(code === 0) {
					if(data == -1 || data.errcode) {
						callback(1);
					} else {
						callback(0, data);
					}
				}
			});
	}

	var getNegoMaxRateurl = baseUrl + "/stationlist_fuzzy?";
	v3StaMonitor.getNegoMaxRate = function(devSN, skipnum, limitnum, callback) {
		baseRequest.commonPost(getNegoMaxRateurl + $.param({
				devSN: devSN,
				skipnum: skipnum,
				limitnum: limitnum
			}), {
				findoption: {
					NegoMaxRate: {
						min: -1,
						max: 10
					}
				},
				sortoption: {}
			},
			5000,
			function(code, data) {
				if(code === 2 || code === 1) {
					return callback(2);
				}
				if(code === 0) {
					if(data == -1 || data.errcode) {
						callback(1);
					} else {
						callback(0, data);
					}
				}
			});
	}

	//终端列表
	//根据mac【批量】获取终端信息 /stamonitor/app/stainfolist?devSN=' + acSN + '&clientMAClist=
	var getTerminalDetailByMacAllUrl = baseUrl + '/app/stainfolist';
	v3StaMonitor.getTerminalDetailByMacAll = function(devSN, clientMacList, callback) {
		baseRequest.commonPost(getTerminalDetailByMacAllUrl, {
			devSN: devSN,
			clientMACList: clientMacList
		}, 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2)
			}
			if(code === 0) {
				if(data.errCode === 0) {
					callback(0, data.clientInfo);
				} else {
					callback(1);
				}
			}
		});
	}

	//基于AP查看终端列表
	var getApListUrl = baseUrl + "/getclientstatisticbyap?";
	v3StaMonitor.getApList = function(devSN, callback) {
		baseRequest.commonGet(getApListUrl + $.param({
			devSN: devSN
		}), 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	var getApDetailUrl = baseUrl + "/getclientstatisticbyap_detail?";
	v3StaMonitor.getApDetail = function(devSN, apName, radioType, skipnum, limitnum, callback) {
		baseRequest.commonGet(getApDetailUrl + $.param({
			devSN: devSN,
			apName: apName,
			bandType: radioType,
			skipnum: skipnum,
			limitnum: limitnum
		}), 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}

	//终端搜索
	var getBySearchInputurl = baseUrl + "/stationlist_page?";
	v3StaMonitor.getBySearchInput = function(devSN, starNum, limitnum, searchCondition, callback) {
		baseRequest.commonPost(getBySearchInputurl + $.param({
				devSN: devSN,
				skipnum: starNum,
				limitnum: limitnum
			}), searchCondition,
			5000,
			function(code, data) {
				if(code === 2 || code === 1) {
					return callback(2);
				}
				if(code === 0) {
					if(data == -1 || data.errcode) {
						callback(1);
					} else {
						callback(0, data);
					}
				}
			});
	}
	//end

	// by zhangfq
	//旧的获取历史宾客接口
	var gethistclientlistUrl = baseUrl + '/gethistclientlist?';
	/**
	 * 获取历史在线终端
	 * @param {String} devSN
	 * @param {Number} skipNum 跳过的个数，从0开始
	 * @param {Number} limitNum 查询的个数，分页大小
	 * @param {Function} callback
	 */
	v3StaMonitor.getHistClientList = function(devSN, skipNum, limitNum, callback) {
		baseRequest.commonGet(gethistclientlistUrl + $.param({
				devSN: devSN,
				limitnum: limitNum,
				skipnum: skipNum
			}),
			function(code, data) {
				if(code === 2 && code === 1) {
					return callback(2)
				}
				if(data == -1 || data.errcode) {
					return callback(1, locale.base.err.request);
				}
				return callback(0, data.clientList);
			});
	};
	//新的获取历史宾客接口
//	var gethistclientlistUrl = baseUrl + '/clientinfo';
//	v3StaMonitor.getHistClientList = function(devSN, skipNum, limitNum, callback){
//		baseRequest.commonPost(gethistclientlistUrl,{
//			"method": "getClientHistory",
//          "param":{
//              "devSN": devSN,
//              "skipNum": skipNum,
//              "limitNum": limitNum
//          }
//		}, 5000, function(code, data) {
//			if(code === 2 || code === 1) {
//				return callback(2)
//			}
//			if(code === 0) {
//				console.log(JSON.stringify(data));
////				if(data.errCode === 0) {
////					callback(0, data.clientInfo);
////				} else {
////					callback(1);
////				}
//			}
//		});
//	};
	
	var getOnlineClientListUrl = baseUrl + '/web/stationlist?';
	/**
	 * 获取在线终端
	 * @param {String} devSN
	 * @param {Function} callback
	 */
	v3StaMonitor.getOnlineClientList = function(devSN, callback) {
		baseRequest.commonGet(getOnlineClientListUrl + $.param({
			devSN: devSN
		}), function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(data == -1 || data.errcode) {
				return callback(1, locale.base.err.request);
			}
			return callback(0, data.clientList);
		});
	};

	// end by zhangfq
	
	//by dongyi
	//基于手机厂商获取终端列表接口
	var getCategoryClientListUrl = baseUrl + '/getclientlist_bymodeorvendor?';
	v3StaMonitor.getCategoryClientList = function(devSN,skipnum,checkdata,callback){
		baseRequest.commonPost(getCategoryClientListUrl + $.param({
			devSN : devSN,
			skipnum : skipnum,
			limitnum : 10,
		}), checkdata, 10000, function(code, data){
			if(code === 0){
				if(data == -1 || data.errcode) {
					callback(1);
				} else {
					callback(0, data.clientList);
				}
			}
			if(code === 1 || code ===2){
				return callback(2);
			}
		})
	}
	//新的终端协商速率分布接口
	var getClientTxUrl = baseUrl + '/clientstatistic_bynegomaxrate';
	v3StaMonitor.getClientTx = function(devSN,NegoMaxRate,callback){
		baseRequest.commonPost(getClientTxUrl,{
			"devSN": devSN,
			"NegoMaxRate": NegoMaxRate
		}, 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.errcode || data == -1) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	
	//新的终端信噪比分布接口
	var getRssiChangeUrl = baseUrl +'/clientstatistic_bysignalstrength';
	v3StaMonitor.getRssiChange = function(devSN,signalStrength, callback) {
		baseRequest.commonPost(getRssiChangeUrl,{
			"devSN": devSN,
			"signalStrength": signalStrength
		}, 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.errcode || data== -1) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	//获取认证用户列表接口
	var getClientverboseUrl = baseUrl + '/getclientverbose_page?';
	v3StaMonitor.getClientverbose = function(devSN,skipNum,limitNum,checkdata,callback) {
		baseRequest.commonPost(getClientverboseUrl + $.param({
			"devSN" : devSN,
			"auth" : 1,
			"skipnum" :skipNum,
			"limitnum" : limitNum,
		}),checkdata, 5000, function(code, data) {
			if(code === 2 || code === 1) {
				return callback(2);
			}
			if(code === 0) {
				if(data.errcode || data== -1) {
					callback(1);
				} else {
					callback(0, data);
				}
			}
		});
	}
	//end by dongyi 

})(mui, window);